define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        _queryString: '',
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zzyy/user_extend/index' + Controller._queryString,
                    add_url: 'zzyy/user_extend/add' + Controller._queryString,
                    edit_url: 'zzyy/user_extend/edit',
                    del_url: 'zzyy/user_extend/del',
                    multi_url: 'zzyy/user_extend/multi',
                    import_url: 'zzyy/user_extend/import',
                    table: 'zzyy_user_extend',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'user.username', title: '用户名', operate: 'LIKE'},
                        {field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
                        {field: 'user.avatar', title: '用户头像', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'balance', title: '余额（元）', operate: 'between'},
                        // {field: 'accept_sms', title: __('Accept_sms'), searchList: {"0":__('Accept_sms 0'),"1":__('Accept_sms 1')}, formatter: Table.api.formatter.normal, operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'wz_button',
                                    text: '余额变化记录',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-check-square',
                                    url: function (row) {
                                        return Fast.api.fixurl('zzyy/user_balance/history?user_id=' + row.user_id)
                                    },
                                    extend: "data-area='[\"60%\", \"60%\"]'",
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            queryString: function () {
                return location.search.replace("dialog=1", "").split('&').filter(function (item) {
                    return !!item;
                }).join("&");
            }
        }
    };
    Controller._queryString = Controller.api.queryString();
    return Controller;
});